/** 操作记录 */

import React, {useEffect, useState} from 'react'
import {message} from 'antd'
import type {ColumnsType} from 'antd/es/table'
import CustomTable from '@/components/Table'
import {getOperatelogList} from '@/service/common'

interface DataType {
	showCancelButton: any
	id: string
	allocationCode: string
	orgId: number
	moveInCompany: number
	moveOutCityName: string
	moveInCityName: string
	allocationStatus: number | string
}

const operationRecord = (props: any) => {
	const {businessId, businessType} = props
	const [dataSourse, setDataSourse] = useState<any[]>([])
	const [loading, setLoading] = useState(false)
	const [total, setTotal] = useState()
	const [params, setParams] = useState({
		current: 1,
		size: 10,
	})

	/** 获取操作记录列表 */
	const getData = () => {
		setLoading(true)
		getOperatelogList({...params, businessType, businessId})
			.then((res: any) => {
				if (res?.success) {
					setDataSourse(res?.data?.records)
					setTotal(res?.data?.total)
					setLoading(false)
				} else {
					setLoading(false)
				}
			})
			.catch((err) => {
				setDataSourse([])
				message.error(err)
				setLoading(false)
			})
	}
	useEffect(() => {
		getData()
	}, [params])

	const columns: ColumnsType<DataType> = [
		{
			title: '操作人',
			dataIndex: 'logPersonname',
			align: 'center',
			width: 100,
		},
		{
			title: '操作内容',
			dataIndex: 'logRemark',
			align: 'center',
			width: 200,
		},
		{
			title: '操作时间',
			dataIndex: 'logTime',
			align: 'center',
			width: 100,
		},
	]

	return (
		<CustomTable
			params={params}
			columns={columns}
			total={total}
			pagination
			callback={(pagination: any) => {
				setParams(pagination)
			}}
			loading={loading}
			dataSource={dataSourse}
		/>
	)
}

export default operationRecord
